﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using System.Collections;
using ECCIT;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using System.IO;

public partial class admin_UKNOW_event_event_comment_add : AdminBasePage
{
    private const string VIEWSTATE_COLUMN_ID = "columnid";
    private const string VIEWSTATE_LAYER_ID = "layerid";
    private const string VIEWSTATE_EventsID = "EventsID";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ViewState[VIEWSTATE_COLUMN_ID] = int.Parse(Request.Params[VIEWSTATE_COLUMN_ID]);
            ViewState[VIEWSTATE_LAYER_ID] = Request.Params[VIEWSTATE_LAYER_ID];
            ViewState[VIEWSTATE_EventsID] = Request.Params[VIEWSTATE_EventsID];
            
            hrefBack.HRef = GetBackUrl();

            infoname.Text = "新增评论";
            IList<MemberModel> CommentMemberlist = new MemberBLL(this.LangID).selectmember();
            foreach (MemberModel membername in CommentMemberlist)
            {
                this.comment_memberID_ddl.Items.Add(new ListItem(membername.AccountName.ToString(),membername.ID.ToString()));
            }
        }

    }
    protected void Sub_click(object sender, EventArgs e)
    {
        int Event_ID = int.Parse(ViewState[VIEWSTATE_EventsID].ToString());
        EventsCommentBLL bll = new EventsCommentBLL(this.LangID);
        EventsCommentModel info = new EventsCommentModel();

        string filename = "";
        string videoName = "";
        string path = Server.MapPath("~/uploadfiles/image/");
        string path0 = Server.MapPath("~/uploadfiles/media/");
        //评论图片上传
        if (file.PostedFile.ContentLength > 0)
        {
            string name = Guid.NewGuid().ToString();
            string ext = file.FileName.Substring(file.FileName.LastIndexOf("."), file.FileName.Length - (file.FileName.LastIndexOf(".")));
            filename = name + ext;
            if (File.Exists(path + filename))
            {
                File.Delete(path + filename);
            }
            else
            {
                file.SaveAs(path + filename);
            }
        }
        //评论视频上传
        if (file0.PostedFile.ContentLength > 0)
        {
            string topname0 = Guid.NewGuid().ToString();
            string flv = file0.FileName.Substring(file0.FileName.LastIndexOf("."), file0.FileName.Length - (file0.FileName.LastIndexOf(".")));
            videoName = topname0 + flv;
            if (File.Exists(path0 + videoName))
            {
                File.Delete(path0 + videoName);
            }
            else
            {
                file0.SaveAs(path0 + videoName);
            }
        }
        info.EventsID = Event_ID;
        info.LanguageID = LangID;
        info.MemberID = int.Parse(comment_memberID_ddl.SelectedValue);
        info.Content = comment_content.Text;
        info.Time = DateTime.Now;

        info.ImagePath = filename;
        //info.ImageUrl = int.Parse(sponsors_ddl.SelectedValue);//
        info.ImageDesc = TextBox1.Text;
        info.ImageName = TextBox2.Text;
        info.ImageTag = TextBox44.Text;

        info.VideoPath = videoName;
        //info.VideoUrl = indextop.SelectedItem.Selected;//
        info.VideoName = TextBox4.Text;
        info.VideoDesc = TextBox5.Text;
        info.VideoTag = TextBox6.Text;

     

        ResultInfo res = bll.Save(info);
        if (res.Result)
        {
            Response.Redirect(GetBackUrl());
        }
        else
        {
            Response.Write("<script>alert('保存失败')</script>");
            Response.Write(res.Message);
        }

    }

    private string GetBackUrl()
    {
        string url = string.Format("event_comment_list.aspx?{0}={1}&{2}={3}&{4}={5}&{6}={7}", VIEWSTATE_COLUMN_ID, ViewState[VIEWSTATE_COLUMN_ID], VIEWSTATE_EventsID, ViewState[VIEWSTATE_EventsID], VIEWSTATE_LAYER_ID, ViewState[VIEWSTATE_LAYER_ID], "langID", this.LangID);
        return url;   
    }
}